
//
//  TWBStatusViewModel.swift
//  weiBo
//
//  Created by 杨雷 on 2016/12/12.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit

class TWBStatusViewModel: NSObject {

    var status: TWBStatus? {
        didSet{
            guard let currentStatus = status else {
                return
            }
            
            
        }
    }
    
    var retweetContent: String?
    
    var mbrankImage: UIImage?
    
    var verifiedTypeImage: UIImage?
    
    var retweetCountContent: String?
    
    var commentCountContent: String?
    
    var unlikeCountContent: String?

    private func handleRetweetContent(status: TWBStatus) {
        
        if status.retweeted_status != nil {
            
            if let name = status.retweeted_status?.user?.screen_name, let text = status.retweeted_status?.text {
                
                retweetContent = "@\(name): \(text)"
                
            }
            
        }
        
    }
    
    private func handleCountContent(count: Int, defaultTitle: String) -> String {
        
        if count > 0 {
            
            if count >= 10000 {
                
                let result = CGFloat(count / 1000) / 10
                
                let str = "\(result)万"
                
                if str.contains(".0") {
                    
                    return str.replacingOccurrences(of: ".0", with: "")
                } else {
                    
                    return str
                }
                
            } else {
                
                return "\(count)"
            }
            
        } else {
            
            return defaultTitle
        }
        
    }
    
    private func handleVerifiedTypeImage(verfiedType: Int) {
        
        switch verfiedType {
            
        case 1:
            
            verifiedTypeImage = #imageLiteral(resourceName: "avatar_vip")
            
        case 2, 3, 5:
            
            verifiedTypeImage = #imageLiteral(resourceName: "avatar_enterprise_vip")
            
        case 220:
            
            verifiedTypeImage = #imageLiteral(resourceName: "avatar_grassroot")
            
        default:
            verifiedTypeImage = nil
        }
        
    }
    
    private func handlembrankImage(mbrank: Int) {
        //  会员等级 1-6
        if mbrank >= 1 && mbrank <= 6 {
            
            mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
        }
        
    }
}
